package com.talkweb.historylib.fraction;

import com.talkweb.historylib.ResourceTable;
import com.talkweb.historylib.provider.ImageListProvider;
import com.talkweb.historylib.utils.ImageItemHelper;
import com.talkweb.securitycamera.common.base.BaseFraction;
import com.talkweb.securitycamera.common.constans.FileType;
import com.talkweb.securitycamera.common.interfaces.entity.IBaseFileEntity;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author SUQI
 * @date 2021/1/28
 * @description 图像历史列表
 **/
public class ImageHistoryListFraction extends BaseFraction {

    private ListContainer listContainerImage;
    private ImageListProvider provider;


    public ImageHistoryListFraction() {
    }

    @Override
    public int getLayoutId() {
        return ResourceTable.Layout_fraction_image_history_list;
    }

    @Override
    public void initializeComponent(Component component) {
        listContainerImage = findComponent(ResourceTable.Id_lc_image);
        List<IBaseFileEntity> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            int finalI = i;
            list.add(new IBaseFileEntity() {
                @Override
                public String getFilePath() {
                    return "/data/local/tmp/hiai/pic1.jpg";
                }

                @Override
                public String getCreateDuration() {
                    return finalI + "s";
                }

                @Override
                public String getFileName() {
                    return "pic1";
                }

                @Override
                public FileType getFileType() {
                    return FileType.FILE_TYPE_IMAGE;
                }
            });
        }
        provider = new ImageListProvider(getFractionAbility());
        listContainerImage.setItemProvider(provider);
        provider.setDataList(ImageItemHelper.formatList(list));
    }

    /**
     * 刷新图片列表界面
     * @param list
     */
    public void refreshImageList(List<IBaseFileEntity> list) {
        List<List<IBaseFileEntity>> formatList = ImageItemHelper.formatList(list);
        getUITaskDispatcher().asyncDispatch(() -> provider.setDataList(formatList));
    }

}
